package com.boot.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    @Value("${business.mq.order-fallback-exchange}")
    private String orderExchange;

    @Value("${business.mq.order-fallback-queue}")
    private String orderQueue;

    @Value("${business.mq.routing-key}")
    private String routingKey;

    @Bean
    public TopicExchange orderFallbackExchange() {
        return new TopicExchange(orderExchange);
    }

    @Bean
    public Queue orderFallbackQueue() {
        return new Queue(orderQueue, true);
    }

    @Bean
    public Binding orderFallbackBinding() {
        return BindingBuilder.bind(orderFallbackQueue())
                .to(orderFallbackExchange())
                .with(routingKey);
    }

    @Bean
    public Jackson2JsonMessageConverter jsonMessageConverter() {
        return new Jackson2JsonMessageConverter();
    }
}
